#include "finddialog.h"
#include "ui_finddialog.h"


FindDialog::FindDialog(MainWindow * w ,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FindDialog)
{
    this->window = w;
    ui->setupUi(this);
}

void FindDialog::findId()
{
    QString str = ui->lineEdit->displayText();
    //QTextCursor cursor = window->editor->document()->find(str);
    cursor = window->editor->document()->find(str);
    QTextCharFormat format;
    format.setBackground(Qt::red);
    cursor.setCharFormat(format);
    //window->editor->setTextCursor(cursor);
}

void FindDialog::findNext()
{
    QString str = ui->lineEdit->displayText();
    //QTextCursor cursor = window->editor->document()->find(str);
    QTextCharFormat format;
    format.setBackground(Qt::white);
    cursor.setCharFormat(format);
    cursor = window->editor->document()->find(str,cursor);
    format.setBackground(Qt::red);
    cursor.setCharFormat(format);
}

FindDialog::~FindDialog()
{
    delete ui;
    //QTextCursor cursor = window->editor->textCursor();
    cursor.atStart();
    cursor.atEnd();
    QTextCharFormat format;
    format.setBackground(Qt::white);
    cursor.setCharFormat(format);
}
